* ---------------------------------------------
* clean regression data
* ---------------------------------------------
clear all

* set up your working directory here
global home_dir ""

cd ${home_dir}

program clean_regdata
	args geo_type
	
	use "./data/processed_notshared/regtable_unemployment_`geo_type'_v2.dta", clear 
	
	* sample drop 
	drop if AgeGrp4 == 0
	
	* adjust some variables 
	tab Race6, gen(race6_nh)
		rename race6_nh1 White_nh 
		rename race6_nh2 Black_nh 
		rename race6_nh3 AIAN_nh 
		rename race6_nh4 AsPI_nh 
		rename race6_nh5 Other_nh
		rename race6_nh6 Hispanic
	
	tab MarStat5, gen(ms)
		rename ms1 Marrd5
		rename ms2 Widow5
		rename ms3 Divor5
		rename ms4 Separ5
		rename ms5 NvMar5
	
	tab AgeGrp4, gen(ag) 
		rename ag1 Age_15_24
		rename ag2 Age_25_44
		rename ag3 Age_45_64
		rename ag4 Age_65_Up
	
	tab empstat, gen(emp)
		rename emp1 Empl 
		rename emp2 UnEmpl 
		rename emp3 NotInLabor 
	
	destring St, replace 
	
	if ("`geo_type'" == "cz") {
		destring cz, replace 
	}
	if ("`geo_type'" == "county") {
		destring county, replace 	
	}
	
	* recode variable 
	label define empstat 1 "Employed" 2 "Unemployed" 3 "NotInLabor"
	label value empstat empstat 
	label var empstat "Employment Status"
	
	label var Female "Female"
	label var Race6 "Race"
	label define race 1 "White" 2 "Black" 3 "AIAN" 4 "Asian" 5 "Other" 6 "Hispanic"
	label value Race6 race 
	
	label var AgeGrp4 "Age Group"
	label define AgeGrp4 1 "Age 15_24" 2 "Age 25_44" 3 "Age 45_64" 4 "Age 65_up"
	label value AgeGrp4 AgeGrp4 
	
	label var agegroup "Age Group (5 years)"
	
	label var MarStat5 "Marital Status"
	label define marstat 1 "Married" 2 "Widowed" 3 "Divorced" 4 "Separated" 5 "Never married"
	label value MarStat5 marstat 
	
	label var EducGroup "Education Group"
	label define EducGroup 1 "less than hs" 2 "HS" 3 "Some college" 4 "BS" 5 "MS up"
	label value EducGroup EducGroup
	
	label var BornUSA "Born in USA"
	
	label var RAT_Female "% Female"
	label var RAT_AgeGrp4_1 "% Age 15_24"
	label var RAT_AgeGrp4_2 "% Age 25_44"
	label var RAT_AgeGrp4_3 "% Age 45_64"
	label var RAT_AgeGrp4_4 "% Age 65_up"
	
	label var RAT_Race6_1 "% White"
	label var RAT_Race6_2 "% Black"
	label var RAT_Race6_3 "% AIAN"
	label var RAT_Race6_4 "% Asian"
	label var RAT_Race6_5 "% Other"
	label var RAT_Race6_6 "% Hispanic"
	
	label var RAT_MarStat5_1 "% Married"
	label var RAT_MarStat5_2 "% Widowed"
	label var RAT_MarStat5_3 "% Divorced"
	label var RAT_MarStat5_4 "% Separated"
	label var RAT_MarStat5_5 "% Never married"
	
	label var RAT_EducGroup_1 "% Educ = less than hs"
	label var RAT_EducGroup_2 "% Educ = hs"
	label var RAT_EducGroup_3 "% Educ = some college"
	label var RAT_EducGroup_4 "% Educ = bs"
	label var RAT_EducGroup_5 "% Educ = ms and up"

	label var RAT_veteran "% Veteran"
	label var RAT_PhysProb "% Physical Problem"
	
	label var RAT_BornUSA "% Born in USA"
	
	label var pop_density "Population Density"
	
	label var std_same_prop_empstat "Employment Sameness"
	label var RAT_Empl "% Employed"
	label var RAT_UnEmpl "% Unemployed"
	label var RAT_NotInLabor "% Not in labor force"
	
	label var Suic "Suicide"
	
	label var EducYear "Years of Education"
	label var PhysProb "Physical Problem"
	label var veteran "Veteran"

	compress
	
	save "./data/processed_notshared/cleaned_regtable_unemployment_`geo_type'_v2.dta", replace 
end 

clean_regdata county
clean_regdata cz

